package cn.com.b2office.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.b2office.dao.SpecialCategoryDao;
import cn.com.b2office.domain.SpecialCategory;

public class SpecialCategoryDaoHibernateImpl extends HibernateDaoSupport
		implements SpecialCategoryDao {

	@SuppressWarnings("unchecked")
	public List<SpecialCategory> findAllSpecialCategory() {
		List<SpecialCategory> list = null;

		Session s = getSession();
		try {
			Query query = s.createQuery("from SpecialCategory");
			query.setCacheable(true);
			list = query.list();
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
		return list;
	}

	public int isInSpecialCategory(String categoryId) {
		int sortwt = -1;
		SpecialCategory sdp = null;
		Session s = getSession();
		try {
			sdp = (SpecialCategory) s.createQuery(
					"from SpecialCategory where categoryId=:categoryId")
					.setString("categoryId", categoryId).uniqueResult();
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
		if (sdp != null)
			sortwt = sdp.getSortWeight();
		return sortwt;
	}
}
